import execjs
import requests

def get_sign(min_behot_time):
    jsFile = open('某头条.js', 'r', encoding='utf-8').read()
    jsx = execjs.compile(jsFile).call('sign',min_behot_time)
    return jsx
min_behot_time = str(1699073324)
headers = {
    "authority": "www.toutiao.com",
    "accept": "application/json, text/plain, */*",
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36",
    "referer": "https://www.toutiao.com/?wid=1699073302718",
    "accept-language": "zh-CN,zh;q=0.9"
}
cookies = {}
while True:
    try:
        print('----------------------------------------------------------------------------------')
        print(min_behot_time)
        print('----------------------------------------------------------------------------------')
        url = "https://www.toutiao.com/api/pc/list/feed?channel_id=3189398999&min_behot_time={}&offset=0&refresh_count=2&category=pc_profile_channel&client_extra_params=%7B%22short_video_item%22:%22filter%22%7D&aid=24&app_name=toutiao_web&_signature={}".format(min_behot_time,get_sign(min_behot_time))
        response = requests.get(url, headers=headers,cookies=cookies)

        print(response.text)
        cookies = response.cookies.get_dict()
        min_behot_time = str(response.json()['data'][0]['behot_time'])
    except Exception as e:
        print(e)


